#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=105;
int n,a[N],dp[N][N][N];
void scan(){
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    return;
}
int work(int k,int lastA,int lastB){
    if(k>n) return 0;
    if(dp[k][lastA][lastB]!=-1) return dp[k][lastA][lastB];
    dp[k][lastA][lastB]=max(work(k+1,k,lastB)+((a[k]==a[lastA]?a[k]:0)),work(k+1,lastA,k)+((a[k]==a[lastB]?a[k]:0)));
    return dp[k][lastA][lastB];
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        scan();
        cout<<work(1,0,0)<<endl;
    }
    return 0;
}